//
//  LJStatusForwardCell.swift
//  LJWeibo
//
//  Created by Raymond on 15/12/23.
//  Copyright © 2015年 liu. All rights reserved.
//

import UIKit
/// 原创微博Cell
class LJStatusForwardCell: LJStatusCell {
    /// 重写父类属性必须实现属性监视器，会先调用父类的属性监视器在调用子类的
    override var status: LJStatus? {
        didSet {
            if let forwardStatus = status?.retweeted_status {
                var text = "@匿名: \(forwardStatus.text!)"
                if forwardStatus.user?.screen_name != nil {
                    text = "@\(forwardStatus.user!.screen_name!): \(forwardStatus.text!)"
                }
                forwardLabel.text = text
            }
        }
    }
    
    /// 准备UI
    override func prepareUI() {
        super.prepareUI()
        // 添加控件
        contentView.addSubview(bkgButton)
        contentView.addSubview(forwardLabel)
        
        // 设置背景在底部
        contentView.sendSubviewToBack(bkgButton)
        // 添加约束
        bkgButton.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -8, y: 8))
        bkgButton.ff_AlignVertical(type: ff_AlignType.TopRight, referView: bottomView, size: nil)
        
        forwardLabel.ff_AlignInner(type: ff_AlignType.TopLeft, referView: bkgButton, size: nil, offset: CGPoint(x: 8, y: 8))
        contentView.addConstraint(NSLayoutConstraint(item: forwardLabel, attribute: NSLayoutAttribute.Width, relatedBy: NSLayoutRelation.Equal, toItem: nil, attribute: NSLayoutAttribute.NotAnAttribute, multiplier: 1, constant: UIScreen.mainScreen().bounds.width - 2 * 8))
        
        let cons = pictureView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 290), offset: CGPoint(x: 0, y: 8))
        pictureViewHeightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        pictureViewWidthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
    }
    
    /// MARK: - 懒加载
    /// 背景
    private lazy var bkgButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.88, alpha: 1)
        return button
    }()
    /// 被转发微博文字
    private lazy var forwardLabel: UILabel = {
        let label = UILabel(textColor: UIColor.darkGrayColor(), fontSize: 14)
        label.numberOfLines = 0
        
        label.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * 8
        return label
    }()
}
